<template>
  <div>
    <el-container class="home-container">
      <el-aside ref="aside" :width="isCollapse ? '64px' : '200px'">
        <el-menu
          router
          ref="menu"
          :collapse="isCollapse"
          :collapse-transition="false"
        >
          <!-- :class="['home-menu' ? 'collapse-menu' : '']" -->
          <div class="logo">
            <i class="el-icon-eleme"></i>
            <h1 v-show="!isCollapse">Manager</h1>
          </div>
          <el-menu-item index="/dashboard">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>

          <el-submenu index="/user">
            <template slot="title">
              <i class="el-icon-s-custom"></i>
              <span>用户管理</span>
            </template>
            <el-menu-item index="/user">
              <span slot="title">用户列表</span>
            </el-menu-item>
            <el-menu-item index="/user/add">
              <span slot="title">添加用户</span>
            </el-menu-item>
            <el-menu-item index="1-3">
              <span slot="title">修改用户</span>
            </el-menu-item>
          </el-submenu>

          <el-submenu index="/category">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>分类管理</span>
            </template>
            <el-menu-item index="/category">
              <span slot="title">查看分类</span>
            </el-menu-item>
            <el-menu-item index="2-2">
              <span slot="title">删除分类</span>
            </el-menu-item>
          </el-submenu>
          <el-menu-item index="/blog">
            <i class="el-icon-document"></i>
            <span slot="title">文章管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header
          ><i
            class="el-icon-s-fold"
            :class="isCollapse ? 'isCollapse' : ''"
            @click="handleCollapse"
          ></i
        ></el-header>
        <el-main><router-view /></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: true,
    }
  },
  mounted() {
    this.$refs['menu'].activeIndex = this.$route.path
  },
  methods: {
    handleCollapse() {
      // 切换状态
      this.isCollapse = !this.isCollapse
      // 改变el-aside的宽度
    },
  },
}
</script>

<style>
.home-container {
  height: 100vh;
}
.el-aside {
  background-color: #fff;
}
.el-header {
  display: flex;
  align-items: center;
  background-color: #fff;
  font-size: 24px;
}
.el-header i {
  transition: all 0.3s;
}
.el-main {
  background-color: #f5f5f5;
}
.logo {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  height: 60px;
  background-color: #409eff;
  font-size: 25px;
  color: #fff;
}
.isCollapse {
  transform: rotate(-180deg);
}
.home-menu {
  width: 200px;
  transition: all 0.3s;
}
.collapse-menu {
  width: 64px;
}
</style>
